package com.lm.security.controller;

import com.lm.security.dto.UserSearchDto;
import com.lm.security.entity.User;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


@RestController
public class UserController {

    @RequestMapping("/me")
    public Object getCurrentUser(@AuthenticationPrincipal UserDetails userDetails,Authentication authentication){
//        return SecurityContextHolder.getContext().getAuthentication();
        return userDetails;
    }


    @RequestMapping("/user")
//    public List<User> user(@RequestParam(required = false) String username){
    public List<User> user(UserSearchDto dto, @PageableDefault(size = 10,page = 1,sort = "user,desc") Pageable pageable){
        System.out.println(dto);
        System.out.println(pageable.getPageSize());
        System.out.println(pageable.getSort());
        System.out.println(pageable.getPageNumber());

        List<User> list = new ArrayList<User>();
        User user = new User();
        list.add(user);
        return list;
   }

}
